#!/usr/bin/env python3

import os

def out(s):
    #  print(s, end='')
    #  sys.stdout.write(s)
    os.write(1, s.encode())

def toNum(num, bit, end='\n'):
    def _toNum(num, bit):
        if num == 0:
            return
        _toNum(num // bit, bit)
        out("0123456789ABCDEF"[num % bit])

    if num == 0:
        out('0')
        return

    if num < 0:
        out('-')
        num *= -1

    out({2: '0b', 8: '0o', 10: '', 16: '0x'}[bit])

    _toNum(num, bit)

    if end:
        out(end)

def main():
    toNum(*[int(x) for x in input("请输入数字和进制数: ").split()])

if __name__ == "__main__":
    main()
